#include<bits/stdc++.h>
#define rep_(i, a, b) for (int i = (a); i <= (b); i++)
#define pii pair<int, int> 
#define int long long
using namespace std;
const int maxn = 3e5 + 10;
int n, m, L, mv;
struct node{
	int d, v, a;
}c[maxn];
int p[maxn], l[maxn], r[maxn];

void solve() {
	cin >> n >> m >> L >> mv;
	rep_(i, 1, n) {
		cin >> c[i].d >> c[i].v >> c[i].a;
	}
	// int dv = mv + 1;
	rep_(i, 1, m) {
		cin >> p[i];
	}
	rep_(i, 1, n) {
		if (c[i].a == 0) {
			if (c[i].v <= mv) {
				l[i] = r[i] = -1;
			} else {
				l[i] = c[i].d;
				r[i] = L;
			}
		} else if (c[i].a > 0) {
			int x;
			if (c[i].v > mv) x = 0;
			else {
				x = floor((double)1.0 * (mv * mv - c[i].v * c[i].v) / 2 / c[i].a);
				while(2 * c[i].a * x + c[i].v * c[i].v <= mv * mv) x++;
			} 
			l[i] = c[i].d + x; r[i] = L;
		} else { // c[i].a < 0
			// assert(c[i].a < 0);
			int x;
			if (c[i].v <= mv) l[i] = r[i] = -1;
			else {
				c[i].a = -c[i].a;
				x = floor((double)1.0 * (c[i].v * c[i].v - mv * mv) / 2 / c[i].a);
				while(2 * c[i].a * x + mv * mv < c[i].v * c[i].v) x++;	

				l[i] = c[i].d, r[i] = min(L, c[i].d + x - 1);
				c[i].a = -c[i].a;
			}
		}
		// cout << l[i] << ' ' << r[i] << endl;
	}
	vector<pii> vec;
	rep_(i, 1, n) {
		int it = lower_bound(p + 1, p + 1 + m, l[i]) - p;
		if (it <= m && p[it] <= r[i]) vec.push_back(pii(l[i], r[i]));
	}
	// cout << (int)vec.size() << endl;
	// for (auto i : vec) {
		// cout << i.first << ' ' << i.second << endl;
	// }
	vector<pii> h;
	for (auto i : vec) {
		h.push_back(pii(i.second, i.first));
	} 
	sort(h.begin(), h.end());
	int ans = 0;
	for (int i = 0, j = 0; i < (int)h.size(); i++) {
		if (p[j] >= h[i].second) continue;
		while(j < m && p[j + 1] <= h[i].first) j++;
		// assert(j <= m);
		ans++;
	}
	cout << (int)vec.size() << ' ' << m - ans << endl;
}
signed main() {
	freopen("detect.in", "r", stdin);
	freopen("detect.out", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int T; cin >> T; 
	rep_(i, 1, T) {
		solve();
	}
	return 0;
}